﻿@using OBUCare.Web.Infrastructure
@using OBUCare.Core.BL
@using OBUCare.Core.DataAccess;
@{ 
    ObuDropDownListHlper ddlHelper = new ObuDropDownListHlper();


    var operatorInfo = UIUtility.GetCurrentUser();


    var menuNames = ViewData["menuName"];


    string agentNO = UIUtility.getAgentByModule(operatorInfo, menuNames.ToString());
     
}
@using (Html.BeginForm("InvoiceSearch", "Report", FormMethod.Post, new { @id = "searchForm" }))
{

    <table>
        <tr>
            <td style="text-align: right;" width="20%">
                开始日期：
            </td>
            <td style="text-align: left" width="20%">
                @Html.Telerik().DatePicker().Name("FromCreatedDate").HtmlAttributes(new { style = "width: 170px" }).OpenOnFocus(true).ShowButton(false).Value(DateTime.Now.ToShortDateString())
            </td>
            <td style="text-align: right" width="20%">
                结束日期：
            </td>
            <td style="text-align: left" width="20%">
                @Html.Telerik().DatePicker().Name("ToCreatedDate").HtmlAttributes(new { style = "width: 170px" }).OpenOnFocus(true).ShowButton(false).Value(DateTime.Now.ToShortDateString())
            </td>
            <td style="text-align: right" width="20%">
                发票类型：
            </td>
            <td style="text-align: left" width="20%">
                @Html.Telerik().DropDownList().Name("InvoiceType").BindTo(ddlHelper.GetDataSource(ConfigMgr.tblInvoiceType, true, UIConstants.AllItems, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems)))
            </td>
        </tr>
        <tr>
            <td style="text-align: right">
                客户编号：
            </td>
            <td style="text-align: left">
                @Html.TextBox("UserNo", "", new { @style = "width:138px;height:15px" })
            </td>
            <td style="text-align: right">
                流水单号：
            </td>
            <td style="text-align: left">
                @Html.TextBox("SERIAL_NO", "", new { @style = "width:138px;height:15px" })
            </td>
            <td style="text-align: right">
                操作员：
            </td>
            <td style="text-align: left">
                @Html.Telerik().DropDownList().Name("Operator").BindTo(ddlHelper.GetOPERATORSByAgentNo(menuNames, UIConstants.AllItems, agentNO, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems)))
            </td>
        </tr>
        <tr>
            <td style="text-align: right">
                营业厅类别：
            </td>
            <td style="text-align: left">
                @Html.Telerik().DropDownList().Name("AgentType").BindTo(ddlHelper.GetAgentTypes(UIConstants.AllItems, false, agentNO, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems))).CascadeTo("Agent")
            </td>
            <td style="text-align: right">
                营业厅：
            </td>
            <td style="text-align: left">
                @*  @Html.Telerik().DropDownList().Name("Agent").HtmlAttributes(new { @style = "Width:230px;" }).ClientEvents(events => events.OnLoad("agentonload")).SelectedIndex(agentNO == "" ? 0 : 1)*@
                @Html.Telerik().DropDownList().Name("Agent").HtmlAttributes(new { @style = "Width:190px;" }).DataBinding(binding => binding.Ajax().Select("_GetAgent", "RepairOrders", new { AgentNo = agentNO }))
            </td>
            <td style="text-align: right;">
                工号：
            </td>
            <td style="text-align: left">
                @Html.TextBox("txtOperator", "", new { @style = "width:50px;height:15px", @MaxLength = 6 })
                (六位工号)
            </td>
        </tr>
        <tr>
            <td colspan="4">
                &nbsp;
            </td>
            <td colspan="2" align="center">
                <input type="button" value="查询" id="btnSearch" />
                @Html.Hidden("searchSql", "", new { @id = "searchSql" })
                @Html.Hidden("agentNO", agentNO, new { @AgentNo = "agentNO" })
                 @Html.Hidden("menuNames", menuNames, new { @id = "menuNames" })
            </td>
        </tr>
    </table>
    
    
}
<script type="text/javascript">

    $().ready(function () {

        $('#btnSearch').click(function () {
            search();
        });

        if ("@agentNO".length != 0) {
            var agentType = $('#AgentType').data('tDropDownList');
            var transferBillStatus = $('#TransferBillStatus').data('tDropDownList');
            agentType.select(1); agentType.disable();
        }
    });

    function agentonload(e) {
        var agent = $('#Agent').data('tDropDownList');
        $.post("/RepairOrders/_GetAgent", { "AgentType": "全部", "AgentNo": "@agentNO" }, function (data) {
            agent.dataBind(data);
            if ("@agentNO" != "") {
                agent.select(1);
            }
            else {
                agent.select(0);
            }
        })
    }

    function search() {

        var form = $("#searchForm");
        dataString = form.serialize();
        $.ajax({
            type: "POST",
            url: form.attr('action'),
            data: dataString,
            cache: false,
            dataType: "json",
            success: function (data) {

                if (data.Success) {
                    //alert('成功');
                    //debugger;
                    var grid = $('#Grid').data('tGrid')
                    $('#searchSql').val(data.Sql)
                    grid.rebind();
                }
                else {
                    alert('失败：' + data.ErrorMsg)
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                var err = XMLHttpRequest + "<br />" + textStatus + "<br />" + errorThrown;
                alert(err);
            }
        });
    }

</script>
@{
    ddlHelper.Dispose();    
}
